define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.form.id = params.fk_role;
	
	//查询分组列表
	$scope.findgroup = function(){
		$scope.form.father_id = 'ROOT';
		//按id查询分组
		httpService.post(app.urls.role_group_selectByType,$scope.form,function(data){
			if("0000" === data.code){
				$scope.groups = data.data;
				$scope.find();
			}else{
				alert(data.msg);
			}
		});
	}
	$scope.findgroup();
	
	$scope.find = function(){
		//按id查询分组
		httpService.post(app.urls.role_group_selectById,$scope.form,function(data){
			if("0000" === data.code){
				$scope.form.name = data.data.name;
				$scope.form.type = data.data.type;
				$scope.form.father_id = data.data.father_id;
				if($scope.form.father_id != 'ROOT'){
					$('.fatherrole').show();
				}
				
//				$scope.types = app.typeList;
//				
//				if($scope.form.type == '1'){
//					$scope.types.splice(0,1);
//				}else if($scope.form.type == '2'){
//					$scope.types.splice(0,1)
//					$scope.types.splice(1,1)
//				}else if($scope.form.type == '3'){
//					$scope.types.splice(0,1)
//					$scope.types.splice(1,1)
//					$scope.types.splice(2,1);
//				}
				
				$scope.$apply();
				
			}else{
				alert(data.msg);
			}
		});
	}
	
//	$scope.findunit = function(){
//		httpService.post(app.urls.role_group_selectByType,$scope.form,function(data){
//			if("0000" === data.code){
//				httpService.post(app.urls.unit_selectType, $scope.form, function(data) {
//					if ("0000" === data.code) {
//						if(data.data.type == '1'){
//							$scope.form.type = '2';
//						}else if(data.data.type == '2'){
//							$scope.form.type = '2';
//						}
//					} else {
//						alert(data.msg);
//					}
//				});
//			}else{
//				alert(data.msg);
//			}
//		});
//	}
//	$scope.findunit();
	
	$scope.saveForm = function(){
			$scope.form.id = params.fk_role;
			if($scope.formCheck()){
				httpService.post(app.urls.role_group_selectIfExit,$scope.form,function(data){
					if("0000" === data.code){
						if(data.data.length == 0){
							httpService.post(app.urls.role_group_update,$scope.form,function(data){
								if("0000" === data.code){
									var data = {id:params.fk_role,type:params.type};
									eventBusService.publish("content.pageRole.reload",data);
									eventBusService.publish("modal.page.close",{});
					    		}else{
					    			alert(data.msg);
					    		}
							});
						}else{
							alert("该分组已存在");
						}
		    		}else{
		    			alert(data.msg);
		    		}
				});
			}
		}
}}});